package com.cskaoyan.service;

import com.cskaoyan.bean.User1;
import com.cskaoyan.bean.collect.AddorDeleteBean;
import com.cskaoyan.bean.collect.CollectListBean;
import com.cskaoyan.bean.collect.CollectListRequestBean;
import com.cskaoyan.bean.collect.WxCollectBean;
import com.cskaoyan.mapper.CollectMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxCollectServiceImpl implements WxCollectService{

    @Autowired
    CollectMapper collectMapper;
    @Override
    public WxCollectBean SelectCollectlist(CollectListRequestBean collectListRequestBean) {
        Subject subject = SecurityUtils.getSubject();
        User1 user1 = (User1) subject.getPrincipal();
        Integer userid = user1.getId();

        Integer type = collectListRequestBean.getType();
        Integer page = collectListRequestBean.getPage();
        Integer size = collectListRequestBean.getSize();
        Integer totalPages=1+page/size;
        WxCollectBean wxCollectBean = new WxCollectBean();

        List<CollectListBean> collectListBeans = collectMapper.selectCollectList(type,userid);
        wxCollectBean.setTotalPages(totalPages);
        wxCollectBean.setCollectList(collectListBeans);
        return wxCollectBean;
    }

    @Override
    public String addordelete(AddorDeleteBean addorDeleteBean) {
        String type = collectMapper.addordelete(addorDeleteBean);
        return type;
    }

    @Override
    public Integer selectIsHaveCollect(AddorDeleteBean addorDeleteBean,Integer userid) {
        Integer i = collectMapper.selectIsHaveCollect(addorDeleteBean,userid);
        return i;
    }

    @Override
    public void deleteCollect(AddorDeleteBean addorDeleteBean,Integer userid) {
        collectMapper.deleteCollect(addorDeleteBean,userid);
    }

    @Override
    public void insertCollect(AddorDeleteBean addorDeleteBean,Integer userid) {
        collectMapper.insertCollect(addorDeleteBean,userid);
    }

    @Override
    public Integer selecteDeleted(AddorDeleteBean addorDeleteBean,Integer userid) {
        Integer deleted = collectMapper.selecteDeleted(addorDeleteBean,userid);
        return deleted;
    }
}
